from tools.common import run_async_script
import asyncio

from ioservice.common.mongo import find_many_docs
from ioservice.const import alumni_col
from tasks.computing import alumni as alumni_computing
from utils.iterutil import generate_batch


async def update_all_alumni_computing_fields():
    """
    统一计算系友的统计数据
    :return:
    """
    alumni = await find_many_docs(alumni_col, {"is_deleted": {"$ne": True}}, projection=["_id"])
    alumni_ids = (str(a['_id']) for a in alumni)
    print(f"total alumni {len(alumni)}")
    for batch in generate_batch(alumni_ids):
        print(f"processing {len(batch)}")
        await asyncio.gather(*[alumni_computing.update_computing_fields(pid) for pid in batch])


if __name__ == '__main__':
    run_async_script(update_all_alumni_computing_fields())
    # run_async_script(alumni_computing.update_computing_fields("62450d3d99ca51104248aa5f"))